import uuid
from django.db import models
from django.utils import timezone


class Project(models.Model):
    """
    项目表
    """
    objects = models.Manager()

    id = models.CharField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name="项目唯一标识", max_length=255)
    name = models.CharField("项目名称", max_length=100, help_text="不超过100个字符")
    description = models.TextField("项目描述", blank=True, null=True)
    thumbnail_url = models.CharField("缩略图URL", default='images/default.png', max_length=200, blank=True, null=True)
    settings = models.JSONField("全局设置", default=dict, help_text="统一尺寸设置等JSON格式配置")
    last_modified = models.DateTimeField("项目内容最后保存时间（自动保存和手动保存）", blank=True, null=True)
    created_at = models.DateTimeField("创建时间", default=timezone.now, db_index=True)
    updated_at = models.DateTimeField("更新时间", auto_now=True)
    auto_save = models.BooleanField("自动保存", default=True)
    auto_save_interval = models.PositiveIntegerField("保存间隔(分钟)", default=5, help_text="单位：分钟")

    class Meta:
        db_table = 'projects'
        verbose_name = '项目表'
        verbose_name_plural = '项目表'
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.name} ({self.id})"
